<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<script type="text/javascript" >
$(function(){
	$('#resTree').tree({
		url: ctx + '/sm/Res!findChildTree.action?_json=json',
	    fit: true,
	    idField: 'id',
	    treeField: 'text'
	});
	
	
	$('#resEdit').bind('click',function(){
		var row = $('#resTree').tree('getSelected');
		if (!row) {
			$.messager.show({
				msg : '请选择一条数据'
			});
			return false;
		}
		CQOA.load('extendDiv',ctx+'/sm/Res!operate.action',{'entity.sid':row.id},function(){
			CQOA.hideDiv('mainDiv');
			CQOA.showDiv('extendDiv');
		});
	});
	
	
	$('#resAdd').bind('click',function(){
		var row = $('#resTree').tree('getSelected');
		if (!row) {
			row =[];
			row.id=0;
		}
		CQOA.load('extendDiv',ctx+'/sm/Res!operate.action',{'entity.pid':row.id},function(){
			CQOA.hideDiv('mainDiv');
			CQOA.showDiv('extendDiv');
		});
	});
	
	$('#resDel').bind('click',function(){
		var row = $('#resTree').tree('getSelected');
		if (!row) {
			$.messager.show({
				msg : '请选择一条数据'
			});
			return false;
		}
		$.messager.confirm('提示信息','你确定要删除这条数据?',function(s){
			if(s){
				postcommit(ctx+'/sm/Res!delete.action',{'entity.sid':row.id},function(o){
					if(o.success){
						$('#resTree').tree('reload',$('#resTree').tree('getParent',row.target).target);
					}
					$.messager.show({
						msg : o.msg
					});
				});
			}
		});
	});
	
	
});

function comeback(){
	CQOA.hideDiv('extendDiv');
	CQOA.showDiv('mainDiv');
};

function res_save(){
	CQOA.formSubmit($('#resOperateForm'),ctx+'/sm/Res!save.action',function(o){
		if(o.success){
			comeback();
			$('#resTree').tree('reload');
		}
		$.messager.show({
			msg : o.msg
		});
	},{});
};



</script>
<div id="mainDiv" class="easyui-layout" fit="true" border="false">
	        <div id="easyui-title" style="display:none">
	            	菜单设置
	        </div>
            <div class="top_toolbar_div" region="north" border="false">                
                <div id="button_index" class="top_toolbar_button_div" border="false">
                    <a href="#" class="easyui-linkbutton" iconCls="icon-add" id="resAdd">新增</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" id="resEdit">修改</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" id="resDel">删除</a>
                </div>
            </div>
            <div  region="center" border="false">
	           <div class="main_content_div" style="width: 95%; height: 100%;overflow: auto;padding-top: 10px;padding-left: 10px;"; region="center" border="false">
               		<ul id="resTree" class="easyui-tree"></ul>
              </div>
           </div>
</div>
<div id="extendDiv" class="easyui-panel" style="display:none;" fit="true" border="false"></div>


